Skip to main content

TermStruct<StructDef>

TermStruct is an other type that is unnecessarely complicated.

This time because it has to mess around with the struct definition; but even so the type definition should not be that hard to understand if we know what is doing

type StructInstance<SCtorDef extends StructCtorDef> = {
readonly [Field in keyof SCtorDef]: UtilityTermOf<ToPType<SCtorDef[Field]>>
}

type TermStruct<SDef extends StructDefinition> = Term<PStruct<SDef>> & {

readonly eqTerm: TermFn<[PStruct<SDef>], PBool>
readonly eq: ( other: Term<PStruct<SDef>> ) => TermBool

} &
IsSingelKey<SDef> extends true ? StructInstance<SDef[keyof SCtorDef]> : {};

even with these semplifications it might seem a bit complex but really all is telling us is that it adds the struct properties (trough Structinstance) only if the struct can only have one single constructor; and adds nothing if it has more.

Infact we already encountered this method while introducing pmatch; we just didn't know that it was an utility term.

it then adds the eq method regardles of the struct definition.

eq

eq

parameter: other type: Term<PStruct<SDef>>

returns: TermBool

equivalent expression:

peqData.$( term as any ).$( other  as any )

data equality